﻿//---------------------------------------------------------------------------------
// Copyright 2011 Microsoft Corporation
// Licensed under the Microsoft Public License (MS-PL) (the "License"); 
// You may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.opensource.org/licenses/ms-pl.html
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR 
// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, 
// INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 
// CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
// MERCHANTABLITY OR NON-INFRINGEMENT. 
// See the Microsoft Public License (MS-PL) for the specific language governing 
// permissions and limitations under the License.
//---------------------------------------------------------------------------------

using System.Windows.Controls;
using System.Windows.Input;
using System.Collections.ObjectModel;
using System.IO;

namespace Microsoft.Telco.Controls.WindowsPhone
{
    /// <summary>
    /// The list of attached files to be sent as MMS
    /// </summary>
    public partial class AttachedFilesList : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AttachedFilesList"/> class.
        /// </summary>
        public AttachedFilesList()
        {
            InitializeComponent();
        }

        #region event handlers
        private void DeleteImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var image = sender as Image;
            var fileName = image.Tag.ToString();
            var files = this.ListFiles.ItemsSource as ObservableCollection<FileInfo>;
            for (int i = 0; i < files.Count; i++)
            {
                var currentFile = files[i];
                if (currentFile.Name == fileName)
                {
                    files.Remove(currentFile);
                    break;
                }
            }
            e.Handled = true; //don't bubble up
        } 
        #endregion
    }
}
